//
//  BaseTableViewController.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/12.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    var userLogin : Bool?
    
    override func loadView() {
        
        userLogin = UserAccountViewModel().isUserLogin
        //判断是否用户已经登录,如果没登录就加载visitor视图
        if userLogin == true
        {
            super.loadView()
        }
        else
        {
            setVisitorLoginView()
        }

    }
    //定义一个全局的对象,可以供子类调用
    var visitorView : VisitorLoginView?
    
    private func setVisitorLoginView()
    {
        visitorView = VisitorLoginView()
        
        //设置代理
        visitorView?.visitorViewDelegate = self
        
        view = visitorView
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
    }
    
    //当点击了登录按钮时候会调用
    func userWillLogin()
    {
        let oauth = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: oauth)
        
        self.presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func userWillRegister()
    {
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }
}
